from django.core.exceptions import ValidationError

from user.models import User


# 校验用户名称
class ValidateUser(User):

    def __call__(self,value):
        user_count = User.objects.filter(username=value).count()
        if user_count > 0:
            raise ValidationError("用户名已被占用，请更换")



